
<!-- link引入 -->
{include file="common::link"}
{include file="common::pagestyle"}
<body>
<div class="x-body">

    <button class="layui-btn layuiadmin-btn-useradmin" onclick="add()" style="margin: 10px"><i class="layui-icon"></i>添加</button>
    <span class="x-right" style="line-height:40px">共有数据：{$count} 条</span>

  <table class="layui-table">
    <thead>
    <tr>
      <th style="text-align: center;">ID</th>
      <th style="text-align: center;">用户名</th>
      <th style="text-align: center;">密码</th>
      <th style="text-align: center;">状态</th>
      <th style="text-align: center;">时间</th>
      <th style="text-align: center;">操作</th>
    </thead>
    <tbody>
    {foreach $res as $v}
    <tr>
        <td style="text-align: center;">{$v.id}</td>
        <td style="text-align: center;">{$v.username}</td>
        <td style="text-align: center;">{$v.password|cut_str=###,10}</td>
        <td style="text-align: center;">
            {if condition="$v.status eq 0"}
            <span class="layui-badge layui-bg-green">正常访问</span>
            {else/}
            <span class="layui-badge">已被禁用</span>
            {/if}
        </td>
        <td style="text-align: center;">{$v.create_time}</td>
        <td class="td-manage" style="text-align: center;">
            <button class="layui-btn layui-btn-xs" onclick="edit({$v.id})"><i class="layui-icon"></i></button>
            <button class="layui-btn layui-btn-xs" onclick="del({$v.id})"><i class="layui-icon"></i></button>
        </td>
    </tr>
    {/foreach}
    </tbody>
  </table>
  <div class="page" style="margin:10px">{$res|raw}</div>

</div>

<!-- js引入 -->
{include file="common::script"}

<script>
  layui.use(['layer'], function () {
    layer = layui.layer;
    $ = layui.jquery;
  });

  /*用户-添加*/
  function add() {
    layer.open({
      maxmin: true,
      title: '添加',
      shade: [0.8, '#393D49'],
      area: ['460px', '350px'],
      type: 2,
      content: 'adduser',
    });
  }

  /*用户-编辑*/
  function edit(id) {
    layer.open({
      maxmin: true,
      title: '编辑',
      shade: [0.8, '#393D49'],
      area: ['460px', '350px'],
      type: 2,
      content: 'edituser?id=' + id,
    });
  }

  /*用户-删除*/
  function del(id) {
    layer.confirm('确认要删除吗？', {
      btn: ['确认', '取消']
    }, function () {
      //发异步删除数据
      $.post('userdel', { 'id': id }, function (res) {
        if (res.code > 0) {
          layer.alert(res.msg, { icon: 5 });
        } else {
          layer.msg(res.msg);
          setTimeout(function () {
            window.location.reload()
          }, 1000);
        }
      }, 'json');
    });
  }


</script>
</body>
